# Contributor: Orhun Parmaksız <orhunparmaksiz@gmail.com>
# Maintainer: Orhun Parmaksız <orhunparmaksiz@gmail.com>
pkgname=repgrep
_pkgname=rgr
pkgver=0.15.0
pkgrel=0
pkgdesc="Interactive command line replacer for ripgrep"
url="https://github.com/acheronfail/repgrep"
# loongarch64: blocked by libc crate
arch="all !loongarch64"
license="MIT OR Apache-2.0 OR Unlicense"
depends="ripgrep"
makedepends="
	cargo
	cargo-auditable
	asciidoctor
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/acheronfail/repgrep/archive/$pkgver.tar.gz"
options="net"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm 755 "target/release/$_pkgname" -t "$pkgdir/usr/bin"
	install -Dm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname"
	install -Dm 644 LICENSE-MIT -t "$pkgdir/usr/share/licenses/$pkgname"
	out_dir=$(find target -name repgrep-stamp -print0 | xargs -0 ls -t | head -n1 | xargs dirname)
	install -Dm 644 "$out_dir/$_pkgname.1" -t "$pkgdir/usr/share/man/man1"

	echo 'complete -F _rg rgr' | install -Dm 644 /dev/stdin \
		"$pkgdir/usr/share/bash-completion/completions/$_pkgname"
	echo 'compdef $_comps[rg] rgr' | install -Dm 644 /dev/stdin \
		"$pkgdir/usr/share/zsh/site-functions/_$_pkgname"
	rg --generate complete-fish | sed -e 's/-c rg/-c rgr/' \
		| install -Dm 644 /dev/stdin \
		"$pkgdir/usr/share/fish/vendor_completions.d/$_pkgname.fish"
}

sha512sums="
dbd56387ee9c1269c000c4992449b71b29942b987ce7f032ee8b556bf2e7f3f81da7a081aa610075c366f5b8447bab39312ebf1375100348c9532ddb75a6b90a  repgrep-0.15.0.tar.gz
"
